class Solution {
     /*
        二分查找：
            找到最后一个小于等于x的数
    */
    public int mySqrt(int x) {
        int l = 0, r = x;
        int ans = 0;
        while(l <= r){
            int mid = (l+r)/2;
            if( (long)mid*mid<=x ){
                ans = mid;
                l = mid+1;
            }else{
                r = mid-1;
            }
        }
        return ans;
    }
}